package com.war.controller.system;

import com.war.pojo.system.Buyer;
import com.war.service.safeManage.UserService;
import com.war.service.system.BuyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/buyer")
public class BuyerController {
    @Autowired(required = false)
    BuyerService buyerService;

    @RequestMapping("/selectName")
    @ResponseBody
    public List<Buyer> selectName(){
        return buyerService.selectName();
    }

    //访问warehouseManage页面
    @RequestMapping("/buyerList")
    public String list(Buyer buyer, ModelMap m){
        //查询分页数据
        HashMap<String, Object> map = buyerService.select(buyer);        //把数据传到前端
        m.put("info",map);
        //把查询条件传到前端
        m.put("CV",buyer.getConValue());
        return "basicDataManage/buyerManage/buyerManage";
    }

    //打开添加页面
    @RequestMapping("/addBuyPage")
    public String addBuyPage(){
        return "basicDataManage/buyerManage/addBuy";
    }

    //打开修改页面
    @RequestMapping("/editBuyPage")
    public String editBuyPage(Buyer buyer, ModelMap m){
        Buyer w = buyerService.selectByid(buyer);
        //把数据传到前端
        m.addAttribute("warehouse",w);
        return "basicDataManage/buyerManage/editBuy";
    }

    //处理修改的ajax请求
    @RequestMapping("/editBuy")
    @ResponseBody
    public HashMap<String,Object> editBuy(Buyer buyer){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = buyerService.editBuy(buyer);
        map.put("info",info);
        return map;
    }

    //处理删除的ajax请求
    @RequestMapping("/delBuy")
    @ResponseBody
    public HashMap<String,Object> delBuy(Buyer buyer){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = buyerService.delBuy(buyer);
        map.put("info",info);
        return map;
    }

    //处理添加用户的ajax请求
    @RequestMapping("/addBuy")
    @ResponseBody
    public HashMap<String,Object> addBuy(Buyer buyer){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = buyerService.addBuy(buyer);
        map.put("info",info);
        return map;
    }

}
